#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using WaveMaster.Holidays.Club.Service;
using WaveMaster.Holidays.Club.Domain;
using System.Configuration;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;
using System.Collections;

#endregion

namespace WaveMaster.Holidays.Club.Web
{
    public partial class UserControlReportTicketDeduction : UserControl
    {
        TravelAgentService m_travelAgentService;
        TicketDeductionService m_ticketDeductionService;
        User m_currentUser;
        MainForm m_mainForm;

        public UserControlReportTicketDeduction(string name, User user, MainForm mainForm)
        {
            InitializeComponent();
            Name = name;
            m_currentUser = user;
            m_mainForm = mainForm;
            m_ticketDeductionService = (TicketDeductionService)ServiceFactory.Instance().GetService(ServiceFactory.TICKET_DEDUCTION_SERVICE);
            m_travelAgentService = (TravelAgentService)ServiceFactory.Instance().GetService(ServiceFactory.TRAVEL_AGENT_SERVICE);
            initToolBarClick();
            initComboDataSource();
            comboBoxTravelAgent.Enabled = user.UserType == UserType.Administrators;
            comboBoxTravelAgent.Text = user.TravelAgent.ToString();
        }

        private void initComboDataSource()
        {
            ArrayList tas = new ArrayList();
            tas.Add(new TravelAgent(0, "ALL"));
            tas.AddRange(m_travelAgentService.LoadAllTravelAgent());
            comboBoxTravelAgent.DataSource = tas;
        }

        private void initToolBarClick()
        {
            toolBarButtonRunReport.Click += new EventHandler(toolBarButtonRunReport_Click);
        }

        void toolBarButtonRunReport_Click(object sender, EventArgs e)
        {
            TravelAgent ta = (TravelAgent)comboBoxTravelAgent.SelectedValue;
            DataSet result = m_ticketDeductionService.ReportTicketDeductionByDateAndTravelAgent(dateTimePickerFrom.Value, dateTimePickerTo.Value, ta.TravelAgentID);
            result.WriteXml(ConfigurationManager.AppSettings["ReportDataTemp"] + "TicketDeductionReport" + m_currentUser.UserID + ".xml", XmlWriteMode.WriteSchema);
            htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?ReportDataSource=TicketDeductionReport" + m_currentUser.UserID + ".xml&ReportFile=TicketDeductionReport.rpt";
            htmlBox1.Update();

            //result.WriteXml(@"D:\Others\Projects\WaveMasterBoardingManagementSystem\TicketDeductionReport.xml", XmlWriteMode.WriteSchema);
            //string reportID = ServiceFactory.GenerateRandomID().ToString();
            //Session["ReportTicketDeductionData" + reportID] = result;
            //Session["ReportTicketDeductionFile" + reportID] = "TicketDeductionReport.rpt";
            //string param1 = "ReportFile=ReportTicketDeductionFile" + reportID;
            //string param2 = "ReportDataSource=ReportTicketDeductionData" + reportID;
            //htmlBox1.Url = ConfigurationManager.AppSettings["URLReport"] + "ReportViewer.aspx?" + param1 + "&" + param2;
            ////htmlBox1.Url = "http://" + this.Context.HttpContext.Request.ServerVariables["SERVER_NAME"] + ":" + this.Context.HttpContext.Request.ServerVariables["SERVER_PORT"] + @"/Report/" + "ReportViewer.aspx?" + param1 + "&" + param2;
            //htmlBox1.Update();
        }
    }
}